Conversation
…to the fileloader module.
|
I didn't manage to get it to work to do |
|
For your circular import, it is caused (from what I understand) by wanting to specify the type (Instrument). In some packages, like numpy, there's a special typing module to avoid this. |
|
Yes, since type checking is everywhere else I think it should be here too since it's best practice to do it. I tried to use |
|
Personally, i would really prefer to be able to write: from pyaml.instrument import Instrument
sr = Instrument.load("tests/config/sr.yaml")
print(sr)It uses a static class method and is much more in an object oriented style and last but not least you hide this class Instrument(object):
"""PyAML top level class"""
@staticmethod
def load(filename:str) -> "Instrument":
return load_instrument(filename)
...The above works perfectly in vscode and provides completion. |
|
For solving this kind of circular import you can: from typing import Union, TYPE_CHECKING
if TYPE_CHECKING:
from pyaml.instrument import Instrument
def load_instrument(filename:str, paths_stack:list=None) -> "Instrument": |
I will try it. Maybe I was then just missing the quotation marks for it to work. |
|
I have added the suggestions from @JeanLucPons. I will now rewrite the tests and then set it ready for review so you can review if it should be merged or not. |
|
Personally I have no objection to merge this PR. As it will break backward compatibility with the frontend, the release number will be increased following #36. So if you want to rename |
|
Also for me the single instrument (or Accelerator, ok for me as well) per yaml config file is also ok. I can help if needed, let me know @TeresiaOlsson |
|
Okay, then I will also add the changes to change the name from Instrument to Accelerator. My plan was to put that in another PR but then I will add it to this too. |
|
I have fixed the tests now and made it ready for review. |
JeanLucPons
left a comment
There was a problem hiding this comment.
Good for me.
Nice job @TeresiaOlsson !
Thanks
I'm attempting to refactor the configuration layer based on my suggestion in the
amlrepository and the comments from the maintainers meeting.In the first step:
PyAMLclass and moved everything related to loading from a file into the fileloader module.load_latticeor create aLatticeobject directly. In this suggestion there is nowload_instrumentto load from file or you can create anInstrumentobject directly.This aim to solve issue #28.